package com.itfitness.application.winnlistdemo;

import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {
    private RecyclerView mRecyclerView;
    private ArrayList<WinnListBean> mWinnlist;//模拟中奖数据
    private Handler mHandler;
    private Runnable mRunnable;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initDatas();
    }

    private void initDatas() {
        if(mWinnlist==null){
            mWinnlist=new ArrayList<>();
        }
        for (int x=0;x<6;x++){
            mWinnlist.add(new WinnListBean("166****123"+x,"iphone"+x));
        }
        mRecyclerView.setAdapter(new MyAdapter(mWinnlist,this));
        mHandler=new Handler();
        mRunnable = new Runnable() {
            @Override
            public void run() {
                mRecyclerView.smoothScrollBy(0,5);
                mHandler.postDelayed(this,200);
            }
        };
        mHandler.post(mRunnable);
    }

    private void initView() {
        mRecyclerView=findViewById(R.id.rv);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if(mHandler!=null){
            mHandler.removeCallbacks(mRunnable);
        }
    }
}
